package com.magina.project.mgdb.controller;


import com.magina.project.mgdb.service.MgdbTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Magina.Hu
 * @since 2019-04-19
 */
@Api(value = "MongoDB_Controller")
@RestController
@RequestMapping("/testMgdb")
public class MongoDBController {

    @Autowired
    private MgdbTemplateService mgdbTemplateService;

    @ApiOperation(value="MongoTemplate的insert/findAll(不带事务)", notes="使用mongoDb的MongoTemplate的操作")
    @GetMapping("/testTemplateMethod")
    public ResponseEntity testTemplateMethod(){
        return ResponseEntity.ok(mgdbTemplateService.testTemplateMethod());
    }
    @ApiOperation(value="MongoTemplate的insert/findAll(带事务)", notes="使用mongoDb的MongoTemplate的事务操作")
    @GetMapping("/testTemplateMethodWithTran")
    public ResponseEntity testTemplateMethodWithTran(){
        return ResponseEntity.ok(mgdbTemplateService.testTemplateMethodWithTran());
    }

    @ApiOperation(value="mgdbRespository的insert/findAll(不带事务)", notes="使用mongoDb的基类Respository的操作")
    @GetMapping("/testRepositoryMehod")
    public ResponseEntity testRepositoryMehod(){
        return ResponseEntity.ok(mgdbTemplateService.testRepositoryMehod());
    }

    @ApiOperation(value="MongoTemplate的remove", notes="使用mongoDb的MongoTemplate的操作")
    @GetMapping("/testRepositoryMehodRemove")
    public ResponseEntity testRepositoryMehodRemove(){
        return ResponseEntity.ok(mgdbTemplateService.testRepositoryMehodRemove());
    }

}

